package com.Service.impl;

import com.Service.ListingService;
import com.dao.ListingMapper;
import com.model.pojo.Listing;
import com.util.GetNumber;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.beans.Transient;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class listingServiceImpl implements ListingService {
    @Resource
    public ListingMapper listingMapper;


    @Override
    public List<Listing> listOf() {

        String str = null;
        String serialNumber = null;
        int big = 0;
        int id=1;
        long time = System.currentTimeMillis();
        Date date = new Date(time);

        String ma = "yyyyMMddHHmmss";

        SimpleDateFormat forma = new SimpleDateFormat(ma);

        String nwdate = forma.format(date);

        List<Listing> list = listingMapper.search();

        if (list.size() == 0) {
            big = 0;

        } else {
            id=list.get(list.size() - 1).getID()+1;

            str = String.valueOf(list.get(list.size() - 1).getListingSerialNumber());

            str.substring(0, 8);
            int num = Integer.valueOf(str.substring(0, 8));

            if (num > Integer.valueOf(GetNumber.today())) {
                big = 0;

            } else if (num == Integer.valueOf(GetNumber.today())) {
                for (int i = 0; i < list.size(); i++) {
                    str = String.valueOf(list.get(i).getListingSerialNumber());


                    if (GetNumber.today().equals(str.substring(0, 8))) {


                        int small = Integer.valueOf(str.substring(14));

                        if (big < small) {
                            big = small;

                        } else if (big > small) {
                            big = big;

                        }


                    }
                }

            }


        }

        serialNumber = nwdate + GetNumber.zero(6, big + 1);

        listingMapper.listOf(id,serialNumber,"1","1","1","未缴费");


        return list;


    }

    @Override
    public List<Listing> listMessage() {
        List<Listing> list=listingMapper.listMessage();

        return list;
    }


}
